a11y: Set an accessible role for GtkLabel
authorMatthias Clasen <mclasen@redhat.com>
Tue, 28 Jul 2020 20:53:19 +0000 (16:53 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 28 Jul 2020 22:16:37 +0000 (18:16 -0400)
Use the label accessible role for GtkLabel. ARIA has some
ominous wording about it going way, but while we have it,
GtkLabel is the obvious candidate for carrying it.

Update the documentation and add a test.

docs/reference/gtk/section-accessibility.md
gtk/gtkenums.h
gtk/gtklabel.c
testsuite/a11y/label.c

index 78cb8c66fa7fc0f65de44165927a53ac998dfd9c..702e6b01d66ea1709d4723225dd2731e852d1eaa 100644 (file)
@@ -52,6 +52,7 @@ Each role name is part of the #GtkAccessibleRole enumeration.
 | `COMBOBOX` | A control that can be expanded to show a list of possible values to select | #GtkComboBox |
 | `DIALOG` | A dialog that prompts the user to enter information or require a response | #GtkDialog and subclasses |
 | `IMG` | An image | #GtkImage, #GtkPicture |
+| `LABEL` | A visible name or caption for a user interface component. | #GtkLabel |
 | `PROGRESS_BAR` | An element that display progress | #GtkProgressBar |
 | `RADIO` | A checkable input in a group of radio roles | #GtkRadioButton |
 | `SCROLLBAR` | A graphical object controlling the scolling of content | #GtkScrollbar |
index 7947e01e82218623345e48fff5e108c7866427e7..ca3a3f883d642aa3237d0e5180e0d089ae737d2d 100644 (file)
@@ -1183,7 +1183,7 @@ typedef enum {
  * @GTK_ACCESSIBLE_ROLE_HEADING: Unused
  * @GTK_ACCESSIBLE_ROLE_IMG: An image.
  * @GTK_ACCESSIBLE_ROLE_INPUT: Unused
- * @GTK_ACCESSIBLE_ROLE_LABEL: Unused
+ * @GTK_ACCESSIBLE_ROLE_LABEL: A visible name or caption for a user interface component.
  * @GTK_ACCESSIBLE_ROLE_LANDMARK: Unused
  * @GTK_ACCESSIBLE_ROLE_LEGEND: Unused
  * @GTK_ACCESSIBLE_ROLE_LINK: Unused
index ae671f088550eadbf9dffed87b6b518a2c92f9cf..453f6023c7a218eb752f9cc67eb5ddf041fe323d 100644 (file)
  * sense with translatable attributes. Use markup embedded in the translatable
  * content instead.
  *
+ * # Accessibility
+ *
+ * GtkLabel uses the #GTK_ACCESSIBLE_ROLE_LABEL role.
+ *
  * # Mnemonics
  *
  * Labels may contain “mnemonics”. Mnemonics are
@@ -1073,6 +1077,7 @@ gtk_label_class_init (GtkLabelClass *class)
                                        NULL);
 
   gtk_widget_class_set_css_name (widget_class, I_("label"));
+  gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_LABEL);
 
   quark_mnemonics_visible_connected = g_quark_from_static_string ("gtk-label-mnemonics-visible-connected");
 
index 29803d990a22f2b1d8a97619415bbb3e7a61d698..1faacaecb5237f9998d865a8c4cca5fd5957151a 100644 (file)
@@ -1,5 +1,17 @@
 #include <gtk/gtk.h>
 
+static void
+label_role (void)
+{
+  GtkWidget *label = gtk_label_new ("a");
+
+  g_object_ref_sink (label);
+
+  gtk_test_accessible_assert_role (GTK_ACCESSIBLE (label), GTK_ACCESSIBLE_ROLE_LABEL);
+
+  g_object_unref (label);
+}
+
 static void
 label_relations (void)
 {
@@ -37,6 +49,7 @@ main (int argc, char *argv[])
 {
   gtk_test_init (&argc, &argv, NULL);
 
+  g_test_add_func ("/a11y/label/role", label_role);
   g_test_add_func ("/a11y/label/relations", label_relations);
 
   return g_test_run ();